package com.github.phoenics.newlives.common.util.alipay;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import lombok.extern.slf4j.Slf4j;

/**
 * 支付宝支付工具
 *
 * @author Phoenics Chow
 * on 2019年11月19日
 */
@Slf4j
public class AlipayUtil {

    private static final String ALIPAY_LOGO = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKTWlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVN3WJP3Fj7f92UPVkLY8LGXbIEAIiOsCMgQWaIQkgBhhBASQMWFiApWFBURnEhVxILVCkidiOKgKLhnQYqIWotVXDjuH9yntX167+3t+9f7vOec5/zOec8PgBESJpHmomoAOVKFPDrYH49PSMTJvYACFUjgBCAQ5svCZwXFAADwA3l4fnSwP/wBr28AAgBw1S4kEsfh/4O6UCZXACCRAOAiEucLAZBSAMguVMgUAMgYALBTs2QKAJQAAGx5fEIiAKoNAOz0ST4FANipk9wXANiiHKkIAI0BAJkoRyQCQLsAYFWBUiwCwMIAoKxAIi4EwK4BgFm2MkcCgL0FAHaOWJAPQGAAgJlCLMwAIDgCAEMeE80DIEwDoDDSv+CpX3CFuEgBAMDLlc2XS9IzFLiV0Bp38vDg4iHiwmyxQmEXKRBmCeQinJebIxNI5wNMzgwAABr50cH+OD+Q5+bk4eZm52zv9MWi/mvwbyI+IfHf/ryMAgQAEE7P79pf5eXWA3DHAbB1v2upWwDaVgBo3/ldM9sJoFoK0Hr5i3k4/EAenqFQyDwdHAoLC+0lYqG9MOOLPv8z4W/gi372/EAe/tt68ABxmkCZrcCjg/1xYW52rlKO58sEQjFu9+cj/seFf/2OKdHiNLFcLBWK8ViJuFAiTcd5uVKRRCHJleIS6X8y8R+W/QmTdw0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GFYjnD5jcviVCW9PQdoGAGP836SSrmX02mC6FVV6+VRfk2wsDVKVmztLs7dWEutigy92fL+Sflub+TSmbWi3+/g/9vP3HQfBpkKRPJlSNZmg8UUclpEXKnN2xIMAl07wZBCRpvuISOixmzPTzy0uKWFGT/Ybrlw+aPLijn22NprrbUiOn7TkZMWceqJvu486FQb5RF8wQIMmLAHTZ4MCyOT6+2xDmr2Zm1oz9scdm/b44axtjHG0xVS2mxMiN085WdNarzJm/0svfzgtwx8IgMwo9YwTkxIt0J8AVFFcZfGWWjyuqfVwy1WCKLz1upSPmsq3dZmObyatNJo1HEuPWsJab6MyFsGDl7ADfXhDislpvRLDuaISxvjYryTv1D1ENumqPmV7soa7IYFahxrSARpFP4PcIpIRBR9VbWgYc9kdc9vTZHOmz1SBtqbi0cEZbbCYmOMlkUxPMmOmLCtYdjQKZfTGYi+r2izvqv8uxZ6QnS8By6POhZ7rjG9rgaYgz73EGSUvT7wzoIPsz/qY2DTXBPv3TrOqJfigvydfhQqE2oCFkU85mRxz3l5dPT46QLRrID/IzNBG0RADuh9qBa8oX5AGZGBqy++ry2drMsL5s6G0s+TkZV3Plck6R8VkN4O/me7eOe6/VGW2uPHx9jvEODL3gXkKP9kRnsXL3+Rd/5j7mFTiry9o1QYU29FHxz5f6NyHzWjIe2vGTxb7NmqDiEw1Jflf5bGd3e1wryfh7fPIygngo8jrR3usqCo5P4T6Rtq+WGcrB5zUlF2CApOe6CvvEnPp4a1Zg3lh66NgTLPOSTTBif126X8CwZrNhJisprqRzzoud5oGoqD5GROUlIw5catSG5dGPv1SGR1B54i9OSuNpgrL915RV/3ypf9MxRPN5ytgiKTWH/7zEt+nwl8sqTwbGiBpyvFiuPPTD7f3N/7gzdtFwUPJac2oQkmve4c4F/q0/Obdgqs8jZo161KkAOU7iYn3rTSAuRWqLgGoQBfmJP2ksGwVaEe4OcH8nV1c/BqTUUff/AwC2la+X53TAKQAAAABJRU5ErkJggg==";
    // 移动支付
    public static String getNewOrderInfoForApp(String out_trade_no, String subject, String body, String total_fee, String partner, String seller_email, String notify_url) {
        StringBuilder sb = new StringBuilder();
        sb.append("partner=\"");
        sb.append(partner);
        sb.append("\"&out_trade_no=\"");
        sb.append(out_trade_no);
        sb.append("\"&subject=\"");
        sb.append(subject);
        sb.append("\"&body=\"");
        sb.append(body);
        sb.append("\"&total_fee=\"");
        sb.append(total_fee);
        sb.append("\"&notify_url=\"");
        sb.append(notify_url);
        sb.append("\"&service=\"mobile.securitypay.pay");
        sb.append("\"&_input_charset=\"UTF-8");
        sb.append("\"&payment_type=\"1");
        sb.append("\"&seller_id=\"");
        sb.append(seller_email);
        sb.append("\"&it_b_pay=\"15d\"");
        return new String(sb);
    }

    // 移动支付
    public static String getOrderStringForApp(String out_trade_no, String subject, String body, String total_fee, String partner, String seller_email, String notify_url, String sign) {
        StringBuilder sb = new StringBuilder();
        sb.append("partner=\"");
        sb.append(partner);
        sb.append("\"&out_trade_no=\"");
        sb.append(out_trade_no);
        sb.append("\"&subject=\"");
        sb.append(subject);
        sb.append("\"&body=\"");
        sb.append(body);
        sb.append("\"&total_fee=\"");
        sb.append(total_fee);
        sb.append("\"&notify_url=\"");
        sb.append(notify_url);
        sb.append("\"&service=\"mobile.securitypay.pay");
        sb.append("\"&_input_charset=\"UTF-8");
        sb.append("\"&payment_type=\"1");
        sb.append("\"&seller_id=\"");
        sb.append(seller_email);
        sb.append("\"&it_b_pay=\"15d");
        sb.append("\"&sign=\"");
        sb.append(sign);
        sb.append("\"&sign_type=\"RSA\"");
        return new String(sb);
    }

    //新版支付宝移动支付
    public static String getOrderForAlipay(
            AlipayAppConfig alipayAppConfig,
            String out_trade_no,
            String total_fee,
            String subject,
            String notify_url) {
        AlipayClient alipayClient = takeAlipayClient(alipayAppConfig);
        AlipayTradeAppPayRequest request = getAlipayTradeAppPayRequest(out_trade_no, total_fee, subject, notify_url);
        try {
            //这里和普通的接口调用不同，使用的是sdkExecute
            AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
            //log.info("Alipay util response ! response : {}", new Object[]{response.getBody()});
            return response.getBody();//就是orderString 可以直接给客户端请求，无需再做处理。
        } catch (AlipayApiException e) {
            e.printStackTrace();
            log.warn("Alipay util error ! e : {}", new Object[]{e});
        }
        return null;
    }

    public static AlipayClient takeAlipayClient(AlipayAppConfig alipayAppConfig) {
        return new DefaultAlipayClient(
                alipayAppConfig.getSererUrl(),
                alipayAppConfig.getPartner(),
                alipayAppConfig.getRsaPrivate(),
                "json",
                alipayAppConfig.getInputCharset(),
                alipayAppConfig.getAliPublicKey(),
                alipayAppConfig.getSignType()
        );
    }

    public static AlipayTradeAppPayRequest getAlipayTradeAppPayRequest(String out_trade_no, String total_fee, String subject, String notify_url) {
        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
        AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
        //SDK已经封装掉了公共参数，这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
        AlipayTradeAppPayModel model = getAlipayTradeAppPayModel(out_trade_no, total_fee, subject);
        request.setBizModel(model);
        request.setNotifyUrl(notify_url);
        return request;
    }



    private static AlipayTradeAppPayModel getAlipayTradeAppPayModel(String out_trade_no, String total_fee, String subject) {
        AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
        model.setBody("筑链");
        model.setSubject(subject);
        model.setOutTradeNo(out_trade_no);
        model.setTimeoutExpress("30m");
        model.setTotalAmount(total_fee);
        model.setProductCode("QUICK_MSECURITY_PAY");
        return model;
    }

}
